package com.baijiaoxi.utils.video;

import lombok.Data;
@Data
public class VideoInfo {
    private Integer targetWidth=400;//截图宽
    private Integer targetHeight=400;//截图高
    private Integer height;//视频高
    private Integer width;//视频宽
    private String length;//视频长度

    public VideoInfo setWidthAndHeigtht(String s) {
        String[] arr = s.split("x");
        this.height = Integer.valueOf(arr[1]);
        this.width = Integer.valueOf(arr[0]);
        this.targetHeight = this.height * this.targetWidth / this.width;
        return this;
    }
    public void setLength(String length) {
        if (length!=null&&!length.isEmpty()) {
            String[] arr = length.split(":");

            int hours = Integer.valueOf(arr[0]);
            int mins = Integer.valueOf(arr[1]);
            int seconds;
            if (arr[2].contains(".")) {
                String[] secondsArr = arr[2].split("\\.");
                if (Integer.valueOf(secondsArr[1]) > 0) {
                    seconds = Integer.valueOf(secondsArr[0]) + 1;
                    if (seconds == 60) {
                        mins += 1;
                        seconds = 0;
                        if (mins == 60) {
                            hours += 1;
                            mins = 0;
                        }
                    }
                } else seconds = Integer.valueOf(secondsArr[0]);
            } else seconds = Integer.valueOf(arr[2]);
            this.length = String.format("%02d", hours) +":"+ String.format("%02d", mins)+":" + String.format("%02d", seconds);
        }
    }

    public static VideoInfo build(){
        return new VideoInfo();
    }
}
